(function () {
  var dialog = function (tempOption) {
    this.option = tempOption
  };
  dialog.prototype.init = function () {
    this.inputTransactionList = [];
    this.inputStatus = 0;
    this.inputType = "text";
    // var obj = {
    //   open: 'init'
    // };
    // this.dealDialog(obj);
  };
  dialog.prototype.open = function () {
    var obj = {
      open: true
    };
    this.dealDialog(obj)
  };
  dialog.prototype.close = function () {
    var obj = {
      open: false
    };
    this.dealDialog(obj)
  };
  dialog.prototype.dealDialog = function (parameter) {
    console.log(this.option.that)
    var dialogObj = this.option.that.data.dialog_plugIn;
    if (dialogObj[this.option.name]) {
      for (var key in parameter) {
        dialogObj[this.option.name][key] = parameter[key];
      }
    }else{ 
      dialogObj[this.option.name] = parameter;
    }
    this.option.that.setData({
      dialog_plugIn: dialogObj
    })
  };
  dialog.prototype.inputBlur = function (e) {
    var dialogObj = this.option.that.data.dialog_plugIn;
    this.inputTransactionList.push(0);
    this.inputTransaction()
  };
  dialog.prototype.inputFocus = function (e) {
    var inputType = "text";
    if (e) {
      if (e.currentTarget.dataset["inputtype"] && e.currentTarget.dataset["inputtype"] == "number") {
        inputType = "number"
      }
    }
    this.inputType = inputType;
    var dialogObj = this.option.that.data.dialog_plugIn;
    this.inputTransactionList.push(1);
    this.inputTransaction()
  };
  dialog.prototype.inputTransaction = function () {
    console.log(this.inputTransactionList);
    for (var i = this.inputTransactionList.length - 1; i >= 0; i--) {
      if (this.inputTransactionList[i] == 0) {
        var dialogObj = this.option.that.data.dialog_plugIn;
        dialogObj[this.option.name]["inputFocus"] = "";
        this.option.that.setData({
          dialog_plugIn: dialogObj
        });
        this.inputTransactionList.splice(i, 1);
        this.inputStatus = 0;
        console.log("blur")
      } else {
        if (this.inputTransactionList[i] == 1) {
          if (this.inputStatus == 0) {
            var dialogObj = this.option.that.data.dialog_plugIn;
            if (this.inputType == "number") {
              dialogObj[this.option.name]["inputFocus"] = "inputNumberFocus"
            } else {
              dialogObj[this.option.name]["inputFocus"] = "inputTextFocus"
            }
            this.option.that.setData({
              dialog_plugIn: dialogObj
            });
            console.log("focus");
            this.inputTransactionList.splice(i, 1);
            this.inputStatus = 1
          }
        }
      }
    }
  };
  module.exports.Dialog = function (tempOption) {
    var tempPanel = new dialog(tempOption);
    tempPanel.init();
    return tempPanel
  }
})();